Shader "NPR/01 OutLine"
{
    Properties
    {
        _BaseColor("Color", Color) = (1, 1, 1, 1)
        _BaseMap("Base Map", 2D) = "white" {}
        _OutLineColor("OutLine Color",Color) =(0,0,0,1)
        _OutlineWidth("Outline Width",Float) =1
    }
    SubShader
    {
        Tags
        {
            "RenderPipeline" = "UniversalPipeline"
            "LightMode" = "UniversalForward"
            "Queue" = "Geometry"
        }
        Cull Off

        HLSLINCLUDE
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

        TEXTURE2D(_BaseMap);
        SAMPLER(sampler_BaseMap);

        CBUFFER_START(UnityPerMaterial)
            half4 _BaseMap_ST;
            half4 _BaseColor;
            half _OutlineWidth;
            half4 _OutLineColor;
        CBUFFER_END
        ENDHLSL

        pass
        {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            struct a2v
            {
                float4 positionOS   : POSITION;
                float2 texcoord     : TEXCOORD;
            };

            struct v2f
            {
                float4 positionCS   : SV_POSITION;
                float2 uv           : TEXCOORD;
            };

            v2f vert(a2v input)
            {
                v2f output;
                output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
                output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);

                return output;
            }

            half4 frag(v2f input):SV_Target
            {
                half3 fianlCol = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv).rgb * _BaseColor.rgb;

                return half4(fianlCol.rgb, 1);
            }
            ENDHLSL
        }

        Pass
        {
            Tags
            {
                "LightMode" = "SRPDefaultUnlit"
            }

            Cull Front

            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag



            struct a2v
            {
                float4 positionOS   : POSITION;
                float3 normalOS     : NORMAL;
                float4 color        :COLOR;
            };

            struct v2f
            {
                float4 positionCS   : SV_POSITION;
                float4 color        : COLOR;
            };


            v2f vert(a2v input)
            {
                v2f output;

                output.positionCS = TransformObjectToHClip(input.positionOS.xyz + input.normalOS * _OutlineWidth * 0.01 * input.color.a);
                output.color = input.color;
                return output;
            }

            half4 frag(v2f input) : SV_TARGET
            {
                return _OutLineColor;
            }
            ENDHLSL
        }
    }
}